package com.ruoyi.web.controller.pv;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pv.domain.PvOrganization;
import com.ruoyi.pv.service.IPvOrganizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织机构Controller
 *
 * @author zzx
 * @date 2023-03-12
 */
@Api("组织机构")
@RestController
@RequestMapping("/pv/organization")
public class PvOrganizationController extends BaseController {
    @Autowired
    private IPvOrganizationService pvOrganizationService;

    /**
     * 查询组织机构列表
     */

    @GetMapping("/list")
    @ApiOperation("查询组织机构列表")
    public TableDataInfo list(PvOrganization pvOrganization) {
        pvOrganization.setReservedOne(getDeptId());
        startPage();
        List<PvOrganization> list = pvOrganizationService.selectPvOrganizationList(pvOrganization);
        return getDataTable(list);
    }

    /**
     * 导出组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('pv:organization:export')")
    @Log(title = "组织机构" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PvOrganization pvOrganization) {
        pvOrganization.setReservedOne(getDeptId());
        List<PvOrganization> list = pvOrganizationService.selectPvOrganizationList(pvOrganization);
        ExcelUtil<PvOrganization> util = new ExcelUtil<PvOrganization>(PvOrganization.class);
        util.exportExcel(response, list, "组织机构数据");
    }

    /**
     * 获取组织机构详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation("获取组织机构详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pvOrganizationService.selectPvOrganizationById(id));
    }

    /**
     * 新增组织机构
     */
    @PreAuthorize("@ss.hasPermi('pv:organization:add')")
    @Log(title = "组织机构" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增组织机构")
    public AjaxResult add(@RequestBody PvOrganization pvOrganization) {
        pvOrganization.setReservedOne(getDeptId());
        return toAjax(pvOrganizationService.insertPvOrganization(pvOrganization));
    }

    /**
     * 修改组织机构
     */
    @PreAuthorize("@ss.hasPermi('pv:organization:edit')")
    @Log(title = "组织机构" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改组织机构")
    public AjaxResult edit(@RequestBody PvOrganization pvOrganization) {
        return toAjax(pvOrganizationService.updatePvOrganization(pvOrganization));
    }

    /**
     * 删除组织机构
     */
    @PreAuthorize("@ss.hasPermi('pv:organization:remove')")
    @Log(title = "组织机构" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除组织机构")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pvOrganizationService.deletePvOrganizationByIds(ids));
    }
}
